// pages/activity/activity.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    shopDesc:[],
    lo2:'',
    la2:'',
    far:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let id=options.id
    let _this=this
    wx.request({
      url: 'http://www.week3.com/index.php/shopInfo',
      data:{id:id},
      success(res){
        console.log(res.data.data)
        _this.setData({shopDesc:res.data.data})
        _this.data.lo2=res.data.data.lo
        _this.data.la2=res.data.data.la
        // _this.setData({la2:res.data.data.la})
      }
    })
    wx.getLocation({
      type: 'gcj02',
      success (res) {
        let la1=res.latitude
        let lo1=res.longitude
        console.log(res)
        let s=_this.distance(la1,lo1,_this.data.la2,_this.data.lo2)
        console.log(s)
        _this.setData({far:s})
      }
     })
  },
  distance: function (la1, lo1, la2, lo2) {
    var La1 = la1 * Math.PI / 180.0;
    var La2 = la2 * Math.PI / 180.0;
    var La3 = La1 - La2;
    var Lb3 = lo1 * Math.PI / 180.0 - lo2 * Math.PI / 180.0;
    var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(La3 / 2), 2) + Math.cos(La1) * Math.cos(La2) * Math.pow(Math.sin(Lb3 / 2), 2)));
    s = s * 6378.137;
    s = Math.round(s * 10000) / 10000;
    s = s.toFixed(2);
    return s;
  },
})